package net.oschina.app.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import net.oschina.app.Myapp;
import net.oschina.app.R;
import net.oschina.app.hjpbean.UserBean;

import butterknife.BindView;
import butterknife.ButterKnife;

import static net.oschina.app.R.id.my_head_portrait;

/**
 * Created by admin on 2017/7/15.
 */

public class MyData extends AppCompatActivity {

    @BindView(my_head_portrait)
    ImageView myHeadPortrait;
    @BindView(R.id.my_name)
    TextView myName;
    @BindView(R.id.data_time_tv)
    TextView dataTimeTv;
    @BindView(R.id.data_position_tv)
    TextView dataPositionTv;
    @BindView(R.id.data_platform_tv)
    TextView dataPlatformTv;
    @BindView(R.id.data_tereitory_tv)
    TextView dataTereitoryTv;
    @BindView(R.id.bu_data)
    Button buData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UserBean userBean = new UserBean();
        setContentView(R.layout.mydata_layout);
        ButterKnife.bind(this);
        userBean = (UserBean) getIntent().getSerializableExtra("userBean");
        if (userBean != null) {
            Picasso.with(Myapp.mApp).load(userBean.getPortrait()).into(myHeadPortrait);
            myName.setText(userBean.getName());
            String jointime = userBean.getJointime();
            String from = userBean.getFrom();
            if (jointime == null) {
                jointime = "-";
            }
            if (from == null) {
                from = "-";
            }
            ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.GRAY);
            SpannableStringBuilder builder1 = new SpannableStringBuilder("加入时间：" + jointime);
            SpannableStringBuilder builder2 = new SpannableStringBuilder("所在地区：" + from);
            builder1.setSpan(colorSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder2.setSpan(colorSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            dataTimeTv.setText(builder1);
            dataPositionTv.setText(builder2);
        }
        buData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"小子上了贼船，还想跑？",Toast.LENGTH_SHORT).show();
            }
        });

    }

}
